/**
 * Created by Administrator on 2016/7/8.
 */
function SetTime(StartTime,EndTime){
    var start = {
        dateCell: StartTime,
        format: 'YYYY-MM-DD ',
        minDate: jeDate.now(0), //设定最小日期为当前日期
        festival:true,
        maxDate: '2099-06-16 ', //最大日期
        isTime: false,
        choosefun: function(datas){
            end.minDate = datas; //开始日选好后，重置结束日的最小日期
        }
    };
    var end = {
        dateCell: EndTime,
        format: 'YYYY-MM-DD ',
        minDate: jeDate.now(0), //设定最小日期为当前日期
        festival:true,
        maxDate: '2099-06-16 ', //最大日期
        isTime: false,
        choosefun: function(datas){
            start.maxDate = datas; //将结束日的初始值设定为开始日的最大日期
        }
    };
    jeDate(start);
    jeDate(end);
};
            function SetDay(today){
                jeDate({
                    dateCell:today,
                    festival:true,
                    format:"YYYY-MM-DD",
                    isTime:false,
                    minDate:jeDate.now(0)
                })
            };


//验证数字
$.validator.addMethod("isNumber", function(value, element) {  //验证数字
    var length = value.length;
    var mobile = /^(1[3|5|8|7])\d{9}$/g;
    return this.optional(element) || (length == 3 && mobile.test(value));
}, "请正确填写,只能为至少3位的数字");
//验证表单
$.validator.addMethod("isMobile", function(value, element) {  //验证手机
    var length = value.length;
    var mobile = /^(1[3|5|8|7])\d{9}$/g;
    return this.optional(element) || (length == 11 && mobile.test(value));
}, "请正确填写您的手机号码");
$.validator.addMethod( "checkEmail",function(value,element){  //验证邮箱
    var myreg = /^[_a-zA-Z0-9\-]+(\.[_a-zA-Z0-9\-]*)*@[a-zA-Z0-9\-]+([\.][a-zA-Z0-9\-]+)+$/;
    if(value !=''){if(!myreg.test(value)){return false;}};
    return true;
} ,  " 请输入有效的E_mail");
$.validator.addMethod("int",function(value,element){//整数
    var int=/^[0-9]*$/g;
    if(value!=''){if(!int.test(value)){return false;}}
},"请输入数字!");
$.validator.addMethod("username",function(value,element){ //验证姓名
    var char=/^([\w.#（）()\-\u4e00-\u9fa5])+$/gi;
    //var char=/^[a-zA-Z\u4e00-\u9fa5]$/;
    if(value !=''){if(!char.test(value)){return false;}}
    return true;
},"允许输入汉字字母及-#");

$.validator.addMethod("checkprice",function(value,element){ //验证价格
        var price=/^[+]?[0-9]+(\.[0-9]+)?$/;
        if(value !=''){if(!price.test(value)){return false;}}
        return true;
    },"请正确输入");

    $.validator.addMethod("check_int", function(value, element) {
    var aint=parseInt(value);
    return aint>=0&& (aint+"")==value;
}, "请输入整数");

$.validator.addMethod("check_ip", function(value, element) {
    var ip = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
    return this.optional(element) || (ip.test(value) && (RegExp.$1 < 256 && RegExp.$2 < 256 && RegExp.$3 < 256 && RegExp.$4 < 256));
}, "IP地址格式错误");



$(".form-horizontal").validate({
    rules:{
        number:{
            required:true,
            check_int:true,
            //digits:true,
            minlength:1
        },
        d_name:{
            required:true,
            minlength:1,
        },
        store_name:{
            required:true,
            minlength:1,
            username:true,
        },
        coupon_name:{
            required:true,
            minlength:1,
            username:true,
        },
        coupon_code:{
            required:true,
            minlength:1,
            check_int:true,
        },
        username:{
            required:true,
            username:true,
        },
        email: {
            required: true,
//                    email: true,
            checkEmail:true
        },
        phone:{
            required:true,
            digits:true,
            isMobile:true
        },
        card_no:{
            required:true,
            digits:true
        },
        password:{
            required:true,
            minlength:6
        },
        price:{
            required:true,
            checkprice:true
        },
        d_price:{
            required:true,
            checkprice:true
        },
        d_setmenu_price:{
            required:false,
            checkprice:true
        },
        bal_value:{
            required:true,
            checkprice:true
        },
        delivered_number:{
            required:true,
            minlength:1,
            check_int:true
        },
        bal_points:{
            required:true,
            check_int:true
        },
        ip_addr:{
            required:true,
            check_ip:true
        },
        cate_name:{
            required:true,
            username:true
        },
        t_name:{
            required:true,
            username:true
        },
        remark_group:{
            required:true,
            username:true
        },
        action_code:{
            required:true
        },
    },
    messages:{
        number:{
            required:"不能为空字符",
            minlength:"请输入（至少1个数字）"
        },
        d_name:{
            required:"不能为空字符",
            minlength:"请输入（至少1个字符）"
        },
        store_name:{
            required:"不能为空字符",
            minlength:"请输入（至少1个字符）"
        },
        username:{
            required:"不能为空字符",
            //minlength:"请输入（至少1个字符）"
        },
        emails: {
            required:"请输入email地址"
        },
        phone:{
            required:"请输入手机号码",
            digits:"请输入数字"
        },
        card_no:{
            required:"请输入数码",
            digits:"请输入整数数码"
        },
        password:{
            required:"请输入密码",
            minlength:"至少输入六位数"
        },
        price:{
            required:"请输入价格"

        },
         d_price:{
            required:"请输入价格",
            checkprice:"请输入正确的价格"
        },
        d_setmenu_price:{
            checkprice:"请输入正确的价格"
        },
        bal_value:{
            required:"请输入余额"
        },
        bal_points:{
            required:"请输入积分",
            check_int:"请正确输入积分"
        },
        ip_addr:{
            required:"请输入IP地址",
            check_int:"请正确输入"
        },
        cate_name:{
            required:"请输入备注",
        },
        t_name:{
            required:"请输入大厅名称",
        },remark_group:{
            required:"请输入备注名称",
        },expiration_date:{
            required:"请选择到期日期",
        },
        coupon_code:{
            required:"请输入优惠卷编码",
        },
        coupon_name:{
            required:"请输入优惠卷名称",
        },
         delivered_number:{
            required:"请输入优惠卷数目",
        },
        action_code:{
            required:"请输入操作密码",
        },
         staff_name:{
            required:"请输入员工名称",
        },
    }
});